home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbtegblt.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  9.0 KB  |  346 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.25;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* $XConsortium: mfbtegblt.c,v 5.5 89/11/21 15:19:41 keith Exp $ */
  27. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  28. /***********************************************************
  29. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  30. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  31.  
  32.                         All Rights Reserved
  33.  
  34. Permission to use, copy, modify, and distribute this software and its 
  35. documentation for any purpose and without fee is hereby granted, 
  36. provided that the above copyright notice appear in all copies and that
  37. both that copyright notice and this permission notice appear in 
  38. supporting documentation, and that the names of Digital or MIT not be
  39. used in advertising or publicity pertaining to distribution of the
  40. software without specific, written prior permission.  
  41.  
  42. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  43. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  44. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  45. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  46. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  47. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  48. SOFTWARE.
  49.  
  50. ******************************************************************/
  51. #include    "X.h"
  52. #include    "Xmd.h"
  53. #include    "Xproto.h"
  54. #include    "fontstruct.h"
  55. #include    "dixfontstr.h"
  56. #include    "gcstruct.h"
  57. #include    "windowstr.h"
  58. #include    "scrnintstr.h"
  59. #include    "pixmapstr.h"
  60. #include    "regionstr.h"
  61. #include    "mfb.h"
  62. #include    "maskbits.h"
  63.  
  64. /*
  65.     this works for fonts with glyphs <= 32 bits wide.
  66.  
  67.     This should be called only with a terminal-emulator font;
  68. this means that the FIXED_METRICS flag is set, and that
  69. glyphbounds == charbounds.
  70.  
  71.     in theory, this goes faster; even if it doesn't, it reduces the
  72. flicker caused by writing a string over itself with image text (since
  73. the background gets repainted per character instead of per string.)
  74. this seems to be important for some converted X10 applications.
  75.  
  76.     Image text looks at the bits in the glyph and the fg and bg in the
  77. GC.  it paints a rectangle, as defined in the protocol dcoument,
  78. and the paints the characters.
  79.  
  80.    to avoid source proliferation, this file is compiled
  81. two times:
  82.     MFBTEGLYPHBLT        OP
  83.     mfbTEGlyphBltWhite        (white text, black bg )
  84.     mfbTEGlyphBltBlack    ~    (black text, white bg )
  85.  
  86. */
  87.  
  88. #if defined(NO_3_60_CG4) && defined(FASTPUTBITS) && defined(FASTGETBITS)
  89. #define FASTCHARS
  90. #endif
  91.  
  92. /*
  93.  * this macro "knows" that only characters <= 8 bits wide will
  94.  * fit this case (which is why it is independent of GLYPHPADBYTES)
  95.  */
  96.  
  97. #if (BITMAP_BIT_ORDER == MSBFirst) && (GLYPHPADBYTES != 4)
  98. #if GLYPHPADBYTES == 1
  99. #define ShiftAmnt   24
  100. #else
  101. #define ShiftAmnt   16
  102. #endif
  103.  
  104. #define GetBits4    c = (*char1++ << ShiftAmnt) | \
  105.             SCRRIGHT (*char2++ << ShiftAmnt, xoff2) | \
  106.             SCRRIGHT (*char3++ << ShiftAmnt, xoff3) | \
  107.             SCRRIGHT (*char4++ << ShiftAmnt, xoff4);
  108. #else
  109. #define GetBits4    c = *char1++ | \
  110.             SCRRIGHT (*char2++, xoff2) | \
  111.             SCRRIGHT (*char3++, xoff3) | \
  112.             SCRRIGHT (*char4++, xoff4);
  113. #endif
  114.  
  115.  
  116. #if GLYPHPADBYTES == 1
  117. typedef    unsigned char    *glyphPointer;
  118. #define USE_LEFTBITS
  119. #endif
  120.  
  121. #if GLYPHPADBYTES == 2
  122. typedef unsigned short    *glyphPointer;
  123. #define USE_LEFTBITS
  124. #endif
  125.  
  126. #if GLYPHPADBYTES == 4
  127. typedef unsigned int    *glyphPointer;
  128. #endif
  129.  
  130. #ifdef USE_LEFTBITS
  131. #define GetBits1    getleftbits (char1, widthGlyph, c); \
  132.             c &= glyphMask; \
  133.             char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  134. #else
  135. #define GetBits1    c = *char1++;
  136. #endif
  137.  
  138. void
  139. MFBTEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  140.     DrawablePtr pDrawable;
  141.     GC         *pGC;
  142.     int     x, y;
  143.     unsigned int nglyph;
  144.     CharInfoPtr *ppci;        /* array of character info */
  145.     unsigned char *pglyphBase;    /* start of array of glyphs */
  146. {
  147.     CharInfoPtr pci;
  148.     FontInfoPtr pfi = pGC->font->pFI;
  149.     int widthDst;
  150.     unsigned int *pdstBase;    /* pointer to longword with top row 
  151.                    of current glyph */
  152.  
  153.     int h;            /* height of glyph and char */
  154.     register int xpos;        /* current x  */
  155.     int ypos;            /* current y */
  156.     int widthGlyph;
  157.  
  158.     int hTmp;            /* counter for height */
  159.     register int startmask, endmask;
  160.     int nfirst;            /* used if glyphs spans a longword boundary */
  161.     BoxRec bbox;        /* for clipping */
  162.     int    widthGlyphs;
  163.     register unsigned int  *dst;
  164.     register unsigned int  c;
  165.     register int        xoff1, xoff2, xoff3, xoff4;
  166.     register glyphPointer   char1, char2, char3, char4;
  167.  
  168. #ifdef USE_LEFTBITS
  169.     register int        glyphMask;
  170.     register unsigned int  tmpSrc;
  171.     register int        glyphBytes;
  172. #endif
  173.  
  174.     if (pDrawable->type == DRAWABLE_WINDOW)
  175.     {
  176.     pdstBase = (unsigned int *)
  177.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  178.     widthDst = (int)
  179.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  180.     }
  181.     else
  182.     {
  183.     pdstBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  184.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  185.     }
  186.  
  187.     xpos = x + pDrawable->x;
  188.     ypos = y + pDrawable->y;
  189.  
  190.     pci = &pfi->maxbounds;
  191.     widthGlyph = pci->metrics.characterWidth;
  192.     h = pfi->fontAscent + pfi->fontDescent;
  193.  
  194.     xpos += pci->metrics.leftSideBearing;
  195.     ypos -= pfi->fontAscent;
  196.  
  197.     bbox.x1 = xpos;
  198.     bbox.x2 = xpos + (widthGlyph * nglyph);
  199.     bbox.y1 = ypos;
  200.     bbox.y2 = ypos + h;
  201.  
  202.     switch ((*pGC->pScreen->RectIn)(
  203.                 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  204.     {
  205.       case rgnPART:
  206.     /* this is the WRONG thing to do, but it works.
  207.        calling the non-terminal text is easy, but slow, given
  208.        what we know about the font.
  209.  
  210.        the right thing to do is something like:
  211.         for each clip rectangle
  212.         compute at which row the glyph starts to be in it,
  213.            and at which row the glyph ceases to be in it
  214.         compute which is the first glyph inside the left
  215.             edge, and the last one inside the right edge
  216.         draw a fractional first glyph, using only
  217.             the rows we know are in
  218.         draw all the whole glyphs, using the appropriate rows
  219.         draw any pieces of the last glyph, using the right rows
  220.  
  221.        this way, the code would take advantage of knowing that
  222.        all glyphs are the same height and don't overlap.
  223.  
  224.        one day...
  225.     */
  226.     CLIPTETEXT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  227.       case rgnOUT:
  228.     return;
  229.     }
  230.     pdstBase += widthDst * ypos;
  231.     widthGlyphs = widthGlyph << 2;
  232.  
  233. #ifdef USE_LEFTBITS
  234.     glyphMask = endtab[widthGlyph];
  235.     glyphBytes = GLYPHWIDTHBYTESPADDED(pci);
  236. #endif
  237.  
  238.     if (nglyph >= 4 && widthGlyphs <= 32)
  239.     {
  240.     while (nglyph >= 4)
  241.     {
  242.         nglyph -= 4;
  243.         xoff1 = xpos & 0x1f;
  244.         xoff2 = widthGlyph;
  245.         xoff3 = xoff2 + widthGlyph;
  246.         xoff4 = xoff3 + widthGlyph;
  247.         char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  248.         char2 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  249.         char3 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  250.         char4 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  251.  
  252.         hTmp = h;
  253.         dst = pdstBase + (xpos >> 5);
  254.  
  255. #ifndef FASTCHARS
  256.         if (xoff1 + widthGlyphs <= 32)
  257.         {
  258.         maskpartialbits (xoff1, widthGlyphs, startmask);
  259. #endif
  260.         while (hTmp--)
  261.         {
  262.             GetBits4
  263. #ifdef FASTCHARS
  264. # if BITMAP_BIT_ORDER == MSBFirst
  265.             c >>= 32 - widthGlyphs;
  266. # endif
  267.             FASTPUTBITS(OP(c), xoff1, widthGlyphs, dst);
  268. #else
  269.             *(dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  270. #endif
  271.             dst += widthDst;
  272.         }
  273. #ifndef FASTCHARS
  274.         }
  275.         else
  276.         {
  277.         mask32bits (xoff1, widthGlyphs, startmask, endmask);
  278.         nfirst = 32 - xoff1;
  279.         while (hTmp--)
  280.         {
  281.             GetBits4
  282.             dst[0] = dst[0] & ~startmask |
  283.                  OP(SCRRIGHT(c,xoff1)) & startmask;
  284.             dst[1] = dst[1] & ~endmask |
  285.                  OP(SCRLEFT(c,nfirst)) & endmask;
  286.             dst += widthDst;
  287.         }
  288.         }
  289. #endif
  290.         xpos += widthGlyphs;
  291.     }
  292.     }
  293.  
  294.     while(nglyph--)
  295.     {
  296.     xoff1 = xpos & 0x1f;
  297.     char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  298.     hTmp = h;
  299.     dst = pdstBase + (xpos >> 5);
  300.  
  301. #ifndef FASTCHARS
  302.     if (xoff1 + widthGlyph <= 32)
  303.     {
  304.         maskpartialbits (xoff1, widthGlyph, startmask);
  305. #endif
  306.         while (hTmp--)
  307.         {
  308. #ifdef FASTCHARS
  309. #ifdef USE_LEFTBITS
  310.         FASTGETBITS (char1,0,widthGlyph,c);
  311.         char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  312. #else
  313.         c = *char1++;
  314. #if BITMAP_BIT_ORDER == MSBFirst
  315.         c >>= 32 - widthGlyph;
  316. #endif
  317. #endif
  318.         FASTPUTBITS (OP(c),xoff1,widthGlyph,dst);
  319. #else
  320.         GetBits1
  321.         (*dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  322. #endif
  323.         dst += widthDst;
  324.         }
  325. #ifndef FASTCHARS
  326.     }
  327.     else
  328.     {
  329.         mask32bits (xoff1, widthGlyph, startmask, endmask);
  330.         nfirst = 32 - xoff1;
  331.         while (hTmp--)
  332.         {
  333.         GetBits1
  334.         dst[0] = dst[0] & ~startmask |
  335.              OP(SCRRIGHT(c,xoff1)) & startmask;
  336.         dst[1] = dst[1] & ~endmask |
  337.              OP(SCRLEFT(c,nfirst)) & endmask;
  338.         dst += widthDst;
  339.         }
  340.     }
  341. #endif
  342.     xpos += widthGlyph;
  343.     }
  344. }
  345. @
  346.